package com.xbongbong.pro.enums.smartsettings.enums;

import com.xbongbong.i18n.util.I18nMessageUtil;
import java.util.ArrayList;
import java.util.List;
import lombok.Getter;

/**
 * @description: 执行策略类型枚举
 * @Author: hongxiao
 * @date: 2019-04-24 14:24
 * @since v1.0
 */
@Getter
public enum StrategyTypeEnum {
    /**
     * 执行策略类型枚举
     */
    ONLY_ONE(1, "enum.strategyType.memo.only_one"),


    DAILY(2, "enum.strategyType.memo.daily"),


    WEEKLY(3, "enum.strategyType.memo.weekly"),


    MONTHLY(4, "enum.strategyType.memo.monthly"),


    ANNUALLY(5, "enum.strategyType.memo.annually"),


    CUSTOM(6, "enum.strategyType.memo.custom"),
    ;

    /**
     * 执行策略类型标识值
     */
    private Integer code;
    /**
     * 执行策略类型描述
     */
    private String memo;

    StrategyTypeEnum(Integer code, String memo) {
        this.code = code;
        this.memo = memo;
    }

    public static StrategyTypeEnum getByCode(Integer code){
        for(StrategyTypeEnum strategyTypeEnum: values()){
            if(strategyTypeEnum.getCode().equals(code)){
                return strategyTypeEnum;
            }
        }
        return null;
    }

    /**
     * 获取全部枚举
     *
     * @return List<StrategyTypeEnum>
     */
    public static List<StrategyTypeEnum> getAllEnum() {
        List<StrategyTypeEnum> list = new ArrayList<>();
        for (StrategyTypeEnum cache : values()) {
            list.add(cache);
        }
        return list;
    }

    public String getMemo() {
        return I18nMessageUtil.getMessage(memo);
    }
}
